import java.io.*;


public class run {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		CharCounter count = new CharCounter();
		Crypto crypt = new Crypto();
		FileReader reader = new FileReader();
		
		InputStream is = count.getClass().getResourceAsStream("/example.txt");
		String text = (reader.convertStreamToString(is));
		int biggest = 0;
		char biggestChar = ' ';
		for(char letter = 'a'; letter<='z'; letter++) {
			int occ = count.getOccurences(letter, text.toLowerCase());
			
			
			if(occ > biggest){
				biggest = occ;
				biggestChar = letter;
			}
			//System.out.print(letter + " " + occ + "\n");
		}
		int offset = biggestChar - 'e';
		boolean action = false;
		Console console = System.console();
		System.out.print("1: Encrypt text \n2: Decrypt text \n: ");
		String input = console.readLine();
		if(input.equals("1")) {
			System.out.print("Choose offset: ");
			input = console.readLine();
			offset = Integer.parseInt(input);
			action = true;
		}
		System.out.print(crypt.crypt(text, offset, action));

	}

}
